package GraphProperties;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import Global.ConstantVariable;
import Global.ConstantVariable.Matlab_ConstantVariables.DrawingSettingsForMultiLineFigures;
import Global.DirectoryStructureAndSettingsClass;
import Matlab.MatlabRelatedWorksClass;
import SyntheticData.syntheticDataGeneratorClass;
import Utility.WorkerUtilityClass;

public abstract class GenericGraphPropertyClass {
	
	protected String matlabFileName;
	protected String fullPathOfTheMatlabFile;
	
	protected String fullPathOfParentDirectoryOfMatlabCode;
	String fullPathOfTheFigureFolder;
	protected String fullPathOfTheTexFileForTheFigure;
	
	
	protected String title;
	
	PropertiesOfGraphClass propertiesIBelongTo;
		
	protected BufferedWriter outForPureRawFile;
	protected BufferedWriter outForRawFile;
	protected BufferedWriter outForMatlabCodeFile;	
	protected BufferedWriter outForMatlabCodeFileLogScale;
	protected BufferedWriter outForTexForMatlabFigureFile;
	
	protected GenericGraphPropertyClass()
	{
		
	}
	
	protected GenericGraphPropertyClass(PropertiesOfGraphClass propertiesIBelongTo)
	{				
		this.propertiesIBelongTo = propertiesIBelongTo;
	}
	
	protected void changeLineFormattingOptionsForMatlabFigure(BufferedWriter out, int type, int xLength, int yLength) throws IOException
	{	
		out.write("lineobj = findobj('type', 'line');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		//out.write("colorOfTheLine = get(lineobj, 'Color');");
		//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		//out.write("set(lineobj, 'MarkerFaceColor', colorOfTheLine);");
		//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		
		
		//out.write("set(lineobj, 'MarkerEdgeColor', 'k');");
		//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		//out.write("set(lineobj, 'MarkerFaceColor', 'g');");
		//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		
		
		if(type!=ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE && type!=ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE &&(xLength<ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_POINTS_FOR_X && yLength<ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_POINTS_FOR_Y))
		{
			out.write("set(lineobj, 'linewidth', 2.4);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("grid on;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("set(lineobj, 'MarkerSize',"+ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.DEFAULT_MARKER_SIZE_FEW_POINTS+");");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);			
		}
		else
		{
			out.write("set(lineobj, 'linewidth', 2.1);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("set(lineobj, 'MarkerSize',"+ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.DEFAULT_MARKER_SIZE_MANY_POINTS+");");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		}
		
				
		//outForMatlabCodeFile.write("set(lineobj, 'linestyle', '--');");		
		//outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
	}
	
	protected void changeMarkerFormattingOptionsForMatlabFigure(BufferedWriter out, int type, int xLength, int yLength) throws IOException
	{
		if(type!=ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE && type!=ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE && (xLength<ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_POINTS_FOR_X && yLength<ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_POINTS_FOR_Y))
		{			
			//out.write("nCrv = length(get(gca,'children'));");
			//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			//out.write("plFigure=findobj(gca,'Type','line');");
			//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			//out.write("nCrv = length(plFigure);");
			//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			//out.write("nCrv = length(plFigure);");
			//out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			
			//out.write("nCrv = length(findall(gca,'type','line'));");
			
			/*
			out.write("if nCrv == 1");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);		
			out.write("\tcolorOfTheLine = get(lineobj, 'Color');");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\tset(lineobj, 'MarkerFaceColor', colorOfTheLine);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("else");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);*/
			
			out.write("markersFaceColorsForTheMultiFigures=[");
			for(int i=0; i<DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_FACE_COLORS_OF_MARKERS_FOR_MULTI_LINE_FIGURES.length; i++)
			{
				out.write("'"+DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_FACE_COLORS_OF_MARKERS_FOR_MULTI_LINE_FIGURES[i]+"'");
				if(i!=DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_MARKER_TYPES_FOR_MULTI_LINE_FIGURES.length-1)
					out.write(",");
			}	
			out.write("];");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);

			/******************/
			out.write("markersTypesForTheMultiFigures=[");
			for(int i=0; i<DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_MARKER_TYPES_FOR_MULTI_LINE_FIGURES.length; i++)
			{
				out.write("'"+DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_MARKER_TYPES_FOR_MULTI_LINE_FIGURES[i]+"'");
				if(i!=DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_MARKER_TYPES_FOR_MULTI_LINE_FIGURES.length-1)
					out.write(",");
			}	
			out.write("];");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);

			out.write("markersEdgeColorsForTheMultiFigures=[");
			for(int i=0; i<DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_EDGE_COLORS_OF_MARKERS_FOR_MULTI_LINE_FIGURES.length; i++)
			{
				out.write("'"+DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_EDGE_COLORS_OF_MARKERS_FOR_MULTI_LINE_FIGURES[i]+"'");
				if(i!=DrawingSettingsForMultiLineFigures.ORDERED_DRAWING_SETTINGS_EDGE_COLORS_OF_MARKERS_FOR_MULTI_LINE_FIGURES.length-1)
					out.write(",");
			}	
			out.write("];");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);

			/******************/
			/*
			out.write("\tlengthOfMarkersFaceColorsForTheMultiFigures = length(markersFaceColorsForTheMultiFigures);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\tlengthOfmarkersTypesForTheMultiFigures = length(markersTypesForTheMultiFigures);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);

			out.write("\tprop_name(1) = {'Marker'};");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\tprop_name(2) = {'MarkerFaceColor'};");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);


			

			out.write("\tfor propCount=1:nCrv");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);

			out.write("\t\tmarkerTypeIndex = mod(propCount, lengthOfmarkersTypesForTheMultiFigures);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\tif markerTypeIndex == 0");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\t\tmarkerTypeIndex = 1;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\tend;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);

			out.write("\t\tmarkerFaceColorIndex = mod(propCount, lengthOfMarkersFaceColorsForTheMultiFigures);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\tif markerFaceColorIndex == 0");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\t\tmarkerFaceColorIndex = 1;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\tend;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\tprop_values(propCount,1) = {markersTypesForTheMultiFigures(markerTypeIndex)};");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\t\tprop_values(propCount,2) = {markersFaceColorsForTheMultiFigures(markerFaceColorIndex)};");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\tend;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			out.write("\tset(plFigure,prop_name,prop_values);");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			/*out.write("\tend;");
			out.write(ConstantVariable.Format_ConstantVariables.LINE_END);*/

			/******************/
		}
	}
	
	protected void changeTextFormattingOptionsForMatlabFigure(BufferedWriter out) throws IOException
	{	
		out.write("textobj = findobj('type', 'text');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(textobj, 'fontunits', 'points');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(textobj, 'fontsize', 16);");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		/*out.write("set(textobj, 'fontweight', 'bold');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);*/
	}
	
	protected void additionalFormattingOptionsForMatlabFigures(BufferedWriter out) throws IOException
	{
		
		out.write("lineobj = findobj('type', 'line');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(lineobj, 'linewidth', 2.4);");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
				
		out.write("set(h, 'MarkerEdgeColor', 'k');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(h, 'MarkerFaceColor', 'g');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(h, 'MarkerSize', 10);");		
		
		out.write("textobj = findobj('type', 'text');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(textobj, 'fontunits', 'points');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		out.write("set(textobj, 'fontsize', 16);");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		/*out.write("set(textobj, 'fontweight', 'bold');");
		out.write(ConstantVariable.Format_ConstantVariables.LINE_END);*/
	}
	
	
	protected BufferedWriter createTexFileForTheGeneratedMatlabFigure(int typeIndex, int fileType)
	{   
		String path = fullPathOfTheFigureFolder
			+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderMatlabFigure.LATEX_FILES_OF_THE_FIGURES;
		
		String fileName = DirectoryStructureAndSettingsClass.getDatasetName()+ConstantVariable.Format_ConstantVariables.DASH_CHAR+typeIndex+ConstantVariable.Format_ConstantVariables.DASH_CHAR;
		
		if(fileType == ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE)
			fileName += "Figure.tex";
		else if(fileType == ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE)
			fileName += "LogScaleFigure.tex";
		else if(fileType == ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE)
			fileName += "SemiLogScaleFigure.tex";		
		else if(fileType == ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE)
			fileName += "WithErrorBarFigure.tex";
		
		fullPathOfTheTexFileForTheFigure = path+fileName;
		
		try {

			File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
			FileWriter fstream;
			fstream = new FileWriter(descFile);
			BufferedWriter out = new BufferedWriter(fstream);
			return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;   
	}
	
	protected void prepareTexFileForTheCreatedMatlabFigure()
	{
		try {
			outForTexForMatlabFigureFile.write("\\clearpage");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			outForTexForMatlabFigureFile.write("\\begin{figure}[ht]");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			outForTexForMatlabFigureFile.write("\\centering");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			outForTexForMatlabFigureFile.write("\\begin{center}");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			outForTexForMatlabFigureFile.write("\\vskip 0.25cm");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			
			String caption = "\\caption{"+title.replace('_','-')+"}";			
			outForTexForMatlabFigureFile.write(caption);
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			
			String figureLabel = "\\label{fig:" + matlabFileName +"}";
			outForTexForMatlabFigureFile.write(figureLabel);
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			
			String graphicsPath = "\\graphicspath{{"+(new File(fullPathOfTheFigureFolder).getAbsolutePath()+"/").replace('\\', '/')+"}}";				
			outForTexForMatlabFigureFile.write(graphicsPath);
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			
			String includeGraphics = "\\includegraphics[scale=0.75]{"+matlabFileName+ConstantVariable.Matlab_ConstantVariables.SUFFIX_OF_THE_MATLAB_FIGURE+"}";				
			outForTexForMatlabFigureFile.write(includeGraphics);
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			
			outForTexForMatlabFigureFile.write("\\end{center}");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
			outForTexForMatlabFigureFile.write("\\end{figure}");
			outForTexForMatlabFigureFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
    protected void createPlotCodeForMatlab(BufferedWriter outForMatlabCodeFile, int type, boolean isForCombo, int order, double[] xArray, double[] yArray, double[] eArray, String titleForTheProperty, String xLabel, String yLabel, String plotType, int distributionPlotType, boolean generateFigure)
    {    	
    	try {
    		
    		if(isForCombo==false || (isForCombo==true && (order==ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_GRAPH || order==ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_AND_LAST_GRAPH)))
    		{
    			outForMatlabCodeFile.write("h = figure;");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("countForTheLines=0;");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("yMaxReal = 0;");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("hold off;");
    		}
    		else
    			outForMatlabCodeFile.write("hold on;");
    		
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		//additionalFormattingOptionsForMatlabFigures(outForMatlabCodeFile);
    		/*outForMatlabCodeFile.write("XdCiteseer=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,27,28,29,30,34,35,51,99]");
    		outForMatlabCodeFile.write("YdPCiteseer=[0.005291005291005291,0.14561287477954143,0.08774250440917107,0.04794973544973545,0.025903880070546736,0.015432098765432098,0.011904761904761904,0.006723985890652557,0.0036375661375661374,0.0026455026455026454,0.0033068783068783067,0.0020943562610229276,0.0018738977072310405,4.409171075837742E-4,3.3068783068783067E-4,9.92063492063492E-4,7.716049382716049E-4,4.409171075837742E-4,2.204585537918871E-4,2.204585537918871E-4,1.1022927689594356E-4,2.204585537918871E-4,1.1022927689594356E-4,2.204585537918871E-4,1.1022927689594356E-4,1.1022927689594356E-4,1.1022927689594356E-4,1.1022927689594356E-4,1.1022927689594356E-4,1.1022927689594356E-4,1.1022927689594356E-4,1.1022927689594356E-4]");
    		outForMatlabCodeFile.write("");
    		outForMatlabCodeFile.write("XdCora=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,26,29,30,31,32,33,34,36,40,42,44,65,74,78,168]");
    		outForMatlabCodeFile.write("YdPCora=[0.04594543387646836,0.05522925350511557,0.05238726790450928,0.03685107995452823,0.026619931792345584,0.012410003789314134,0.007768093974990527,0.005399772641151952,0.0023683213338385753,0.0024630541871921183,0.001326259946949602,0.0017051913603637742,4.7366426676771507E-4,5.683971201212581E-4,5.683971201212581E-4,6.63129973474801E-4,7.578628268283441E-4,2.8419856006062905E-4,4.7366426676771507E-4,2.8419856006062905E-4,9.473285335354301E-5,2.8419856006062905E-4,9.473285335354301E-5,9.473285335354301E-5,1.8946570670708602E-4,9.473285335354301E-5,1.8946570670708602E-4,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5,9.473285335354301E-5]");
    		outForMatlabCodeFile.write("");*/
    		
    		String xAxisValues="XValues=[";		
    		for(int i=0; i<xArray.length;i++)
    		{
    			xAxisValues = xAxisValues + xArray[i];
    			if(i!=xArray.length-1)
    				xAxisValues = xAxisValues + ",";
    				
    		}
    		xAxisValues += "];";    		
    		outForMatlabCodeFile.write(xAxisValues);
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		if(distributionPlotType==ConstantVariable.Matlab_ConstantVariables.DistributionType.CDF_TYPE)
    			yArray = Utility.WorkerUtilityClass.getCdfFormPdf(yArray);
    		
    		String yAxisValues="YValues=[";		
    		for(int i=0; i<yArray.length;i++)
    		{
    			yAxisValues = yAxisValues + yArray[i];
    			if(i!=yArray.length-1)
    				yAxisValues = yAxisValues + ",";
    		}
    		yAxisValues += "];";    		
    		outForMatlabCodeFile.write(yAxisValues);
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		if(eArray!=null)
    		{
    			String ErrorbarValues="EValues=[";		
    			for(int i=0; i<eArray.length;i++)
    			{
    				ErrorbarValues = ErrorbarValues + eArray[i];
    				if(i!=eArray.length-1)
    					ErrorbarValues = ErrorbarValues + ",";

    			}
    			ErrorbarValues += "];";

    			outForMatlabCodeFile.write(ErrorbarValues);
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		}
    		
    		outForMatlabCodeFile.write("countForTheLines=countForTheLines+1;");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		changeMarkerFormattingOptionsForMatlabFigure(outForMatlabCodeFile, type, xArray.length, yArray.length);
    		
    		outForMatlabCodeFile.write("plFigure=");
    		if(type == ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE)
    			outForMatlabCodeFile.write("plot");
    		else if(type == ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE)
    			outForMatlabCodeFile.write("loglog");
    		else if(type == ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE)
    			outForMatlabCodeFile.write("semilogy");
    		else if(type == ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE)
    			outForMatlabCodeFile.write("errorbar");
    		
    		outForMatlabCodeFile.write("(XValues, YValues,");
    		
    		if(type == ConstantVariable.Matlab_ConstantVariables.ScaleType.ERRORBAR_LINEAR_SCALE)
    			outForMatlabCodeFile.write(" EValues,");
    		
    		outForMatlabCodeFile.write("'");
    			
    		
    		outForMatlabCodeFile.write(plotType);

    		outForMatlabCodeFile.write("');");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		if(type!=ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE && type!=ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE && (xArray.length<ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_POINTS_FOR_X && yArray.length<ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_POINTS_FOR_Y))
    		{
    			outForMatlabCodeFile.write("colorOfTheLine = get(plFigure, 'Color');");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			//outForMatlabCodeFile.write("set(plFigure,'Marker',markersTypesForTheMultiFigures(countForTheLines),'MarkerFaceColor',markersFaceColorsForTheMultiFigures(countForTheLines));");
    			outForMatlabCodeFile.write("markerTypeIndex = mod(countForTheLines, length(markersTypesForTheMultiFigures));");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("if markerTypeIndex == 0");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("\t\tmarkerTypeIndex = 1;");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("end;");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			
    			outForMatlabCodeFile.write("set(plFigure,'Marker',markersTypesForTheMultiFigures(markerTypeIndex),'MarkerFaceColor', colorOfTheLine);");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		}
    		
    		
    		double yMax = WorkerUtilityClass.findMaxForTheGivenVector(yArray);
    		double yMin = WorkerUtilityClass.findMinForTheGivenVector(yArray);
    		double eMax;
    		
    		    		
    		if(eArray!=null)
    		{	
    			eMax=WorkerUtilityClass.findMaxForTheGivenVector(eArray);    			
    			yMax += eMax;
    		}
    		
    		yMax= yMax +((yMax-yMin)*0.1);
    		
    		outForMatlabCodeFile.write("yMax ="+yMax+";");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		outForMatlabCodeFile.write("if yMax > yMaxReal");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		outForMatlabCodeFile.write("\tyMaxReal = yMax;");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		outForMatlabCodeFile.write("end;");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		
    		
    		outForMatlabCodeFile.write("axis([0 200 0  yMaxReal]);");
    		//outForMatlabCodeFile.write("0" +" "+ yMax +"]);");
    		
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		outForMatlabCodeFile.write("axis 'auto x';");
    		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    		
    		if(isForCombo==false || (isForCombo==true && (order==ConstantVariable.Matlab_ConstantVariables.GraphOrderType.LAST_GRAPH || order==ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_AND_LAST_GRAPH)))
    		{
    			changeLineFormattingOptionsForMatlabFigure(outForMatlabCodeFile, type, xArray.length, yArray.length);
    			//changeMarkerFormattingOptionsForMatlabFigure(outForMatlabCodeFile, type, xArray.length, yArray.length);
    			title=titleForTheProperty+"("+ DirectoryStructureAndSettingsClass.getDatasetName().replace('_', '-');

    			if(isForCombo)
    				title = title + (" Content/Link");
    			else
    			{
    				if(propertiesIBelongTo==null || propertiesIBelongTo.edgeType == ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
    					title = title + (" Content");
    				else
    					title = title + (" Link");
    			}
    			title = title  +")";
    			
    			
    			outForMatlabCodeFile.write("if countForTheLines < "+ ConstantVariable.Matlab_ConstantVariables.OtherSettingsForFigures.MIN_NUMBER_OF_LINES_TO_DECIDE_GRAPH_IS_TOGETHER_TYPE);
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("\ttitle('"+title+"');");    			
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("else");    			
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("\ttitle('"+titleForTheProperty+" Synthetic Datasets(ms="+syntheticDataGeneratorClass.getNumberOfSharedBits() +")');");    			
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			outForMatlabCodeFile.write("end;");
    			outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			
    			    			
    			outForMatlabCodeFile.write("xlabel('"+xLabel+"');");
        		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
        		
        		outForMatlabCodeFile.write("ylabel('"+yLabel+"');");
        		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
        		
        		changeTextFormattingOptionsForMatlabFigure(outForMatlabCodeFile);
        		
        		if(isForCombo && propertiesIBelongTo!=null)
    			{
    				outForMatlabCodeFile.write("legend('Link', 'Content', 'Location', 'Best');");
    				outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    			}
    			
    	   		outForMatlabCodeFile.write("print(h, '-dpng', '");    		
    	   		outForMatlabCodeFile.write("../");
    	   		outForMatlabCodeFile.write(ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_FIGURE_DATA_FOLDER_NAME+matlabFileName+ConstantVariable.Matlab_ConstantVariables.SUFFIX_OF_THE_MATLAB_FIGURE);
    	   		outForMatlabCodeFile.write("');");
    	   		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    	   		outForMatlabCodeFile.write("exit;");
    	   		outForMatlabCodeFile.write(ConstantVariable.Format_ConstantVariables.LINE_END);
    	   		outForMatlabCodeFile.flush();
    	   		
    	   		fullPathOfTheFigureFolder = fullPathOfParentDirectoryOfMatlabCode
    			+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_FIGURE_DATA_FOLDER_NAME;

    	   		if(generateFigure)
    	   			MatlabRelatedWorksClass.executeMatlabWithFile(fullPathOfTheMatlabFile, fullPathOfTheFigureFolder, matlabFileName);
    	   		
    		}
    		
			//outForMatlabCodeFile.write("h = legend('Citeseer','Cora','Synthetic', 3); ");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    protected void copyTexForTheFigureTo(String fileName, boolean isTooNecessary)
    {
    	Utility.FileUtilityClass.copyFile(fullPathOfTheTexFileForTheFigure, ConstantVariable.DefaultDirectoryNamesConstants.ROOT_DIRECTORY+
				ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderRootDirectory.LATEST_RESULTS_DIRECTORY +
				ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderLatestResultsDirectory.GENERAL_RESULTS_DIRECTORY+
				fileName, false, true);
    	
    	
    	/************************************/
    	
    	String fileAccordingToImportance;
    	
    	if(isTooNecessary==true)
    		fileAccordingToImportance = ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.MATLAB_FIGURES_TEX_IMPORTANT_RSLTS_ALL_IN_ONE_FILENAME;
    	else
    		fileAccordingToImportance = ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.MATLAB_FIGURES_TEX_RSLTS_ALL_IN_ONE_FILENAME;
    	
    	Utility.FileUtilityClass.copyFile(fullPathOfTheTexFileForTheFigure, ConstantVariable.DefaultDirectoryNamesConstants.ROOT_DIRECTORY+
				ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderRootDirectory.LATEST_RESULTS_DIRECTORY +
				ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderLatestResultsDirectory.GENERAL_RESULTS_DIRECTORY+
				fileAccordingToImportance, false, true);
    	
    	/************************************/    	
    }
}
